package com.zhoug.chart3.formatters;

import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.zhoug.chart3.utils.MPChartUtils;

/**
 * 限制x,y轴上文字的 长度
 *
 * @Author: zhoug
 * @Date: 2023/4/3
 * @Description:
 */
public abstract class MPAbsValueFormatter extends ValueFormatter {
    private int limitTextLength = 0;//最多显示几个文字

    public abstract String getAxisLabelNotLimitLength(float value, AxisBase axis);

    public void setTextMaxLength(int labelMaxLength) {
        this.limitTextLength = labelMaxLength;
    }

    public int getTextMaxLength() {
        return limitTextLength;
    }

    protected String getAxisLabelLimit(float value, AxisBase axis){
        String label = getAxisLabelNotLimitLength(value, axis);
        return MPChartUtils.ellipsizeEnd(label, limitTextLength);
    }

}
